#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        if (n <= 15){
            int a[n+1];
            for (int i=1; i<=n; i++)
                cin >> a[i];
            a[0] = -1;
            int s=0;
            for (int i=0; i<(1<<n); i++){
                int w=0, l[2]={0, 0};
                for (int j=1; j<=n; j++){
                    if (l[((i & (1 << (j - 1))) > 0)])
                        if (a[l[((i&(1<<(j-1)))>0)]] == a[j])
                            w += a[j];
                    l[((i&(1<<(j-1)))>0)] = j;
                }
                s = max(s, w);
            }
            cout << s << '\n';
        }
        else
            cout << 0 << '\n';
    }
    return 0;
}
